<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据维护</title>
    <meta name="keywords" content="数据维护">
    <meta name="description" content="数据维护">
    <link rel="shortcut icon" href="favicon.ico">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/bootstrap/css/bootstrap.min.css'"
          href="../asset/js/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/fonts/iconfont.css'"
          href="../asset/css/fonts/iconfont.css" rel="stylesheet"/>
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/jqgrid/ui.jqgridffe4.css'"
          href="../asset/js/plugins/jqgrid/ui.jqgridffe4.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/animate.min.css'" href="../asset/css/animate.min.css"
          rel="stylesheet"/>
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/style.min862f.css'"
          href="../asset/css/style.min862f.css" rel="stylesheet"/>
    <link rel="stylesheet" th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/ztree/css/zTreeStyle/zTreeStyle.css'"
          href="../asset/js/ztree/css/zTreeStyle/zTreeStyle.css"/>
</head>
<body class="gray-bg" style="height: 100%">
<div class="row animated fadeInRight" style="height: 100%">
    <div class="col-sm-2"
         style="padding-left: 0px;padding-right: 0px; overflow-x: scroll;height: 100%;background-color: white">
        <div class="ibox">
            <div class="ibox-title">企业</div>
            <div class="ibox-content">
                <ul id="tree" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="col-sm-2" style="padding-left: 5px;padding-right: 0px; overflow-x: scroll;height: 100%;">
        <div class="ibox" style="height: 100%;background-color: white">
            <div class="ibox-title">父字典</div>
            <div class="ibox-content">
                <ul id="treeParentDic" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="col-sm-8" style="padding-left: 5px">
        <div class="ibox ">
            <div class="ibox-title ">
                <div class="row">
                    <form class="form-inline" id="formSearch">
                        <div class="col-sm-8 form-group">
                            <label style="width: 60px">名称</label>
                            <input type="text" name="label" placeholder="请输入名称" class="form-control">
                        </div>
                        <div class="col-sm-4 form-group">
                            <button id="btnRest" class="btn btn-primary btn-xs skin_blue_buttom"
                                    style="float: right; margin-left: 10px" type="button"><i
                                    class="icon egojit-front icon-add"></i>&nbsp;重置
                            </button>
                            <button id="btnSearch" class="btn btn-warning btn-xs" type="button"
                                    style="float: right;"><i class="icon egojit-front icon-search"></i>&nbsp;搜索
                            </button>

                        </div>

                    </form>
                </div>

            </div>
            <div class="ibox-content" style="padding-top: 10px">
                <div id="listOprBox" class="row" style="margin-bottom: 10px">
                    <button id="btnAdd" onclick="add()" class="btn btn-primary btn_no_radius btn-xs " type="button">
                        <i class="icon egojit-front icon-add"></i>&nbsp;配置数据
                    </button>
                </div>
                <div class="jqGrid_wrapper">
                    <table id="table_list"></table>
                    <div id="pager_list"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/jquery/jQuery-2.2.0.min.js'"
        src="../asset/js/jquery/jQuery-2.2.0.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/bootstrap/js/bootstrap.min.js'"
        src="../asset/js/bootstrap/js/bootstrap.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/peity/jquery.peity.min.js'"
        src="../asset/js/plugins/peity/jquery.peity.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/jqgrid/i18n/grid.locale-cnffe4.js'"
        src="../asset/js/plugins/jqgrid/i18n/grid.locale-cnffe4.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/jqgrid/jquery.jqGrid.minffe4.js'"
        src="../asset/js/plugins/jqgrid/jquery.jqGrid.minffe4.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/layer/layer.js'"
        src="../asset/js/plugins/layer/layer.js"></script>

<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/ztree/js/jquery.ztree.core.min.js'"
        src="../asset/js/ztree/js/jquery.ztree.core.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/ztree/js/jquery.ztree.excheck.min.js'"
        src="../asset/js/ztree/js/jquery.ztree.excheck.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/comm.js'" src="../asset/js/comm.js"></script>


<!--<script src="js/content.min.js?v=1.0.0"></script>-->
<script type="text/javascript">
    var $jqGridObj;
    var companyId = undefined;
    //删除
    function del(id) {
        var selectIds = [];
        if (!id || id.length <= 0) {
            selectIds = $jqGridObj.list.jqGrid('getGridParam', 'selarrrow');
            console.log(selectIds);
        } else {
            selectIds.push(id);
        }
        if (selectIds == null || selectIds.length < 1) {
            app.tip("请选择数据!");
            return;
        }
        app.confirm("确定删除该数据？", function () {
            app.post("/admin/role/delete", {ids: JSON.stringify(selectIds)}, function (data) {
                app.close();
                app.tip("删除成功！");
                $jqGridObj.list.trigger("reloadGrid");
            })
        })
    };

    //新增
    function add() {
        if (!companyId || companyId.length <= 0) {
            app.tip("请选择企业");
            return;
        }
        app.windows("编辑", "/admin/companyDic/edit?companyId=" + companyId, "300px", "500px");
    }




    //机构的组合
    function getNamesStr(treeNode) {
        var names = "";
        var parentNode = treeNode.getParentNode();
        if (parentNode != null) {
            names = getNamesStr(parentNode) + "," + parentNode.name;
        }

        return names;
    }


    /**
     * 初始化父字典
     * @param companyId
     */
    function initDicTree(companyId) {
        var settingDic = {
            async: {
                enable: true,
                url: "/admin/companyDic/tree?companyId=" + companyId,
                type: "get"
            },
            view: {
                selectedMulti: false,
                showLine: true
            },
            callback: {
                onClick: function (event, treeId, treeNode) {
                    $jqGridObj.refresh({"companyId": companyId, "parentId": treeNode.dicId});
                }
                ,
                onAsyncSuccess: function (event, treeId, treeNode, msg) {
                    var treeObj = $.fn.zTree.getZTreeObj(treeId);
                    treeObj.expandAll(true);
                    var nodes = treeObj.getNodes();
                    if (nodes && nodes.length > 0) {
                        treeObj.selectNode(nodes[0]);
                        $jqGridObj.refresh({"companyId": companyId, "parentId": nodes[0].dicId});
                    }
                }
            }
        };
        zTreeObjDic = $.fn.zTree.init($("#treeParentDic"), settingDic);
    }


    $(document).ready(function () {
        //列表初始化
        $jqGridObj = app.list({
            url: "/admin/companyDic/index",
            colNames: ["名称", "编码", "描述"],
            colModel: [{
                name: "label",
                index: "label",
                width: 70
            }, {
                name: "value",
                index: "value",
                width: 70
            },
                {
                    name: "description",
                    index: "description",

                }
            ]
        });
        //初始化树结构
        var setting = {
            async: {
                enable: true,
                url: "/admin/office/getCompanysTree"
            },
            view: {
                selectedMulti: false,
                showLine: true
            },
            callback: {
                onClick: function (event, treeId, treeNode) {
                    // $jqGridObj.refresh({"companyId": treeNode.id});
                    companyId=treeNode.id;
                    $jqGridObj.list.clearGridData();
                    initDicTree(companyId)
                },
                onAsyncSuccess: function (event, treeId, treeNode, msg) {
                    var treeObj = $.fn.zTree.getZTreeObj(treeId);
                    treeObj.expandAll(true);
                    var nodes = treeObj.getNodes();
                    if (nodes && nodes.length > 0) {
                        treeObj.selectNode(nodes[0]);
                        companyId=nodes[0].id;
                        initDicTree(companyId)
                    }
                }
            }
        };
        zTreeObj = $.fn.zTree.init($("#tree"), setting);


    });
</script>
</body>
</html>
